package controllers;

import java.util.List;

import models.domain.ContractItem;
import play.*;
import play.db.jpa.Transactional;
import play.mvc.*;
import controllers.service.*;
import views.html.subscriptions.*;

public class Subscriptions extends Controller {

	@Transactional
	public static Result list(int id) {
		
		ManageSubscriptionsService service = new ManageSubscriptionsService();
		
		List<ContractItem> subscriptions = service.getContractSubscriptions(id);
		
		return ok(list.render(subscriptions));
	}

	@Transactional
	public static Result add() {
		
		ManageSubscriptionsService service = new ManageSubscriptionsService();
		
		List<ContractItem> subscriptions = service.getAvailableSubscriptions();
		
		return ok(add.render(subscriptions));
	}
	
	@Transactional
	public static Result save(int subscriptionId) {
		
		ManageSubscriptionsService service = new ManageSubscriptionsService();
		
		service.addContractSubscription(1, subscriptionId);
		
		return redirect("/contracts/"+1);
	}
	
	@Transactional
	public static Result remove(int id) {
		
		return ok("not removed, go back");
	}

}